#include <math.h>
#include <iostream>
#include <string>
using std::cout;
using std::endl;
using std::string;

class Figure{
public:
    virtual string getName() const = 0;
    virtual double getArea() const = 0;
};

void display(Figure & fig){
    cout << fig.getName();
    cout << "的面积：";
    cout << fig.getArea() << endl;
}

class Rectangle
: public Figure
{
public:
    Rectangle(double len,double wid)
    : _length(len)
    , _width(wid)
    {}

    string getName() const override{
        return "矩形";
    }

    double getArea() const override{
        return _length * _width;
    }
private:
    double _length;
    double _width;
};

class Circle
: public Figure
{
public:
    Circle(double rad)
    : _radius(rad)
    {}

    string getName() const override{
        return "圆形";
    }

    double getArea() const override{
        return _radius * _radius * PI;
    }
private:
    static constexpr double PI = 3.14;
    double _radius;
};

class Triangle
: public Figure
{
public:
    Triangle(double a,double b,double c)
    : _a(a)
    , _b(b)
    , _c(c)
    {}

    string getName() const override{
        return "三角形";
    }

    double getArea() const override{
        double p = (_a + _b + _c)/2;
        return sqrt(p * (p - _a) * (p - _b) * (p - _c));
    }

private:
    double _a;
    double _b;
    double _c;
};

void test0(){
    Rectangle rt(2,5);
    display(rt);
    Circle cl(2);
    display(cl);
    Triangle ta(5,12,13);
    display(ta);

}

int main(void){
    test0();
    return 0;
}
